package com.zhq.user.action;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionSupport;
import com.zhq.Interface.user.action.IUserAction;
import com.zhq.Interface.user.service.IUserService;
import com.zhq.user.entity.User;

/**
 * 
 * <p></p>
 * @author zhanghanqing 2013-11-15 下午10:54:17
 * @version V1.0   
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify by user: {修改人} 2013-11-15
 * @modify by reason:{方法名}:{原因}
 */
public class UserAction extends ActionSupport implements IUserAction {

	/**
     * 序列化ID
     */
    private static final long serialVersionUID = 7453571701865808734L;
	@Autowired
	private  IUserService userService;
	private String nameString;
	private String pwdString;
	
	public String login() {
		List<User> users = userService.fetchUsers();
		int id = 0;
        for (User user : users) {
        	 if (nameString.equals(user.getUserName())) {
     	        id = user.getId();  
     	        break;
             }
        }
       
        if (userService.isExist(id)) {
	        System.out.println("success!");	
	        return SUCCESS;
        }
        System.out.println("fail");
        return "fail";
		
	}
	
    public String getNameString() {
    	return nameString;
    }
	
    public void setNameString(String nameString) {
    	this.nameString = nameString;
    }
	
    public String getPwdString() {
    	return pwdString;
    }
	
    public void setPwdString(String pwdString) {
    	this.pwdString = pwdString;
    }

	
    public void setUserService(IUserService userService) {
    	this.userService = userService;
    }
}
